import unittest
from api.employee import EmployeeAPI
from utils import common_assert


class TestEmploy(unittest.TestCase):
    employee_id = None
    # employee_id = 1522062795636539392
    # 前置处理
    def setUp(self):
        self.employee_api = EmployeeAPI()

    def test01_add_employee(self):
        add_employee_data = {
            "username": "tom1739t9",
            "mobile": "15039152188",
            "timeOfEntry": "2020-07-09",
            "formOfEmployment": 1,
            "workNumber": "11521",
            "departmentName": "销售",
            "departmentId": "1266699057968001085",
            "correctionTime": "2020-07-30T16:00:00.000Z"
        }
        response = self.employee_api.add_employee(add_employee_data)
        print(response.json())
        # 添加断言
        # self.assertEqual(200, response.status_code)
        # self.assertEqual(True,response.json().get("success"))
        # self.assertEqual(10000, response.json().get("code"))
        # self.assertIn("操作成功", response.json().get("message"))
        common_assert(self, response, 200, True, 10000, "操作成功")

        #提取员工id
        TestEmploy.employee_id = response.json().get("data").get("id")
        print(TestEmploy.employee_id)

    def test02_put_employee(self):
        put_employee_data = {
            "username": "tome2899"
        }
        response = self.employee_api.put_employee(employee_id=TestEmploy.employee_id,put_employee_data=put_employee_data)
        print(response.json())
        # self.assertEqual(200, response.status_code)
        # self.assertEqual(True, response.json().get("success"))
        # self.assertEqual(10000, response.json().get("code"))
        # self.assertIn("操作成功", response.json().get("message"))
        common_assert(self, response, 200, True, 10000, "操作成功")

    def test03_get_employee(self):
        response = self.employee_api.get_employee(employee_id=TestEmploy.employee_id)
        print(response.json())
        # self.assertEqual(200, response.status_code)
        # self.assertEqual(True, response.json().get("success"))
        # self.assertEqual(10000, response.json().get("code"))
        # self.assertIn("操作成功", response.json().get("message"))
        common_assert(self, response, 200, True, 10000, "操作成功")

    def test04_delete_employee(self):
        response = self.employee_api.delete_employ(TestEmploy.employee_id)
        print(response.json())
        # self.assertEqual(200, response.status_code)
        # self.assertEqual(True, response.json().get("success"))
        # self.assertEqual(10000, response.json().get("code"))
        # self.assertIn("操作成功", response.json().get("message"))
        common_assert(self, response, 200, True, 10000, "操作成功")


